import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'
import { WxUserService } from './wx-user.service'
import { BaseController } from '@/base/base.controller'
import { Role, WxUser } from '@prisma/client'
import { WxUserDto } from './dto/wx-user.dto'
import { LoginWxUserDto } from './dto/login-wx-user.dto'
import { ApiTags } from '@nestjs/swagger'
import { LvToken } from '@/decorator/token.decorator'

@ApiTags('微信用户')
@Controller('wx-user')
export class WxUserController extends BaseController<WxUser, WxUserDto> {
  constructor(private readonly wxUserService: WxUserService) {
    super(wxUserService)
  }

  @Post('login')
  async wxUserLogin(@Body() dto: LoginWxUserDto) {
    return await this.wxUserService.wxUserLogin(dto)
  }

  @Patch('role/:id')
  async changeRole(@Param('id') id: string, @Body() dto: { role: Role }) {
    return await this.wxUserService.changeRole(id, dto.role)
  }

  @Get('phone')
  async getUserByPhone(@Param('phone') phone: string) {
    return await this.wxUserService.getUserByPhone(phone)
  }

  @Get('new/:id')
  async getNewUser(@Param('id') id: string) {
    return await this.wxUserService.getNewUser(id)
  }

  @Get('token/:id')
  async checkToken(@LvToken() token: string, @Param('id') id: string) {
    return await this.wxUserService.checkToken(token, id)
  }
}
